<?php
require_once ('HtmlPurifier/HTMLPurifier.auto.php');
/**
 * 
 * The application's starting point
 * @author griever
 *
 */
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {
	
	/**
	 * The starting point of our application, used for
	 * registering common variables
	 * (non-PHPdoc)
	 * @see library/Zend/Application/Bootstrap/Zend_Application_Bootstrap_Bootstrap::run()
	 */
	public function run() {
		$this->registerRouter ();
		$this->registerExceptionHandler ();
		$this->registerHelpers ();
		$this->setupMail ();
		$this->registerCache ();
		parent::run ();
	}
	
	public function registerCache() {
		require_once 'models/CacheManagerFactory.php';
		$manager = CacheManagerFactory::getManager ();
		$outputCache = array ('frontend' => array ('name' => 'Output', 'options' => array ('lifetime' => 86400 ) ), 'backend' => array ('name' => 'Apc' ) );
		$manager->setCacheTemplate ( 'outputCache', $outputCache );
	}
	
	public function registerRouter() {
		$front = $this->getResource ( 'FrontController' );
		$router = $front->getRouter ();
		$this->addRoute ( $router );
	}
	
	public function addRoute($router) {
		$router->addRoute ( 'login-router', new Zend_Controller_Router_Route_Static ( 'login', array ('controller' => 'user', 'action' => 'login' ) ) );
		$router->addRoute ( 'register-router', new Zend_Controller_Router_Route_Static ( 'register', array ('controller' => 'user', 'action' => 'register' ) ) );
	}
	
	public function registerExceptionHandler() {
		$front = $this->getResource ( 'FrontController' );
		require_once ('controllers/Exceptions/Handler/Standard.php');
		$front->setErrorHandler ( new Exception_Handler_Standard () );
	}
	
	/**
	 *
	 * Register Controller helper classes, so that they can be used by
	 * the Controllers
	 */
	public function registerHelpers() {
		Zend_Controller_Action_HelperBroker::addPath ( 'controllers/Action/Helper', 'Custom_Helper' );
	}
	
	/**
	 *
	 * Setup mail configuration
	 */
	public function setupMail() {
//		$config = array ('auth' => 'login', 'ssl' => 'ssl', 'port' => 465, 'username' => 'bkprofile@bkprofile.com', 'password' => 'bkprofilebk@2010' );
//		$trans = new Zend_Mail_Transport_Smtp ( '127.0.0.1', $config );
		$trans = new Zend_Mail_Transport_Sendmail (  );
		Zend_Mail::setDefaultTransport ( $trans );
	}
}

